#include <iostream>
#include <string.h>


void _MegerSort(int* a, int left, int right,int*temp)
{
	if (right <= left)
	{
		return;
	}
	int mid = left + (right - left) / 2;
	_MegerSort(a, left, mid, temp);
	_MegerSort(a, mid + 1, right, temp);
 
	int begin1 = left, end1 = mid;
	int begin2 = mid + 1, end2 = right;
	int i = left;
	while (begin1 <= end1 && begin2 <= end2)
	{
		if (a[begin1] > a[begin2])
		{
			temp[i++] = a[begin2++];
		}
		else
		{
			temp[i++] = a[begin1++];
		}
	}
	while (begin1 <= end1)
	{
		temp[i++] = a[begin1++];
	}
 
	while (begin2 <= end2)
	{
		temp[i++] = a[begin2++];
	}
 
	memcpy(a + left, temp + left, sizeof(int) * (right - left + 1));
}

int main()
{
    int a[10]={5,3,6,9,7,1,0,2,4,10};
    int temp[10]={0};
    _MegerSort(a,0,9,temp);
    for(int i=0;i<10;i++)
    {
        std::cout<<a[i]<<" ";
    }
    std::cout<<std::endl;
    return 0;
}